package com.supermarket.domain.strategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 折扣价格策略
 */
public class DiscountPriceStrategy implements PriceCalculationStrategy {
    private final BigDecimal discountRate; // 折扣率（如0.8表示8折）

    public DiscountPriceStrategy(BigDecimal discountRate) {
        this.discountRate = discountRate;
    }

    @Override
    public BigDecimal calculate(BigDecimal pricePerJin, BigDecimal quantity) {
        return pricePerJin.multiply(quantity)
                .multiply(discountRate)
                .setScale(2, RoundingMode.HALF_UP);
    }
}